<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\store\model\jia;

use app\common\model\jia\SurveyLog as SurveyLogModel;

/**
 * 文章分类模型
 * Class Time
 * @package app\store\model\article
 */
class SurveyLog extends SurveyLogModel {

	public function getListAll(array $param = []) {
		$filter = [];
		// 查询参数
		$params = $this->setQueryDefaultValue($param, [
			'title' => '', // 文章标题
			'categoryId' => 0, // 文章分类id
			'status' => -1, // 文章状态
			'betweenTime' => [], // 起止时间
		]);
		$params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']];
		$params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
		if (!empty($params['title'])) {
			$filter[] = ['content', 'like', '%' . $params['title'] . '%'];
		}
		// 起止时间
		if (!empty($params['betweenTime'])) {
			$times = between_time($params['betweenTime']);
			$filter[] = ['create_time', '>=', $times['start_time']];
			$filter[] = ['create_time', '<', $times['end_time'] + 86400];
		}
		$list = $this->where($filter)
			->order('create_time desc')
			->select()->toArray();

		$lists = [];

		foreach ($list as $key => $value) {
			$contents = $value['content'];
			foreach ($contents as $kk => $content) {
				if ($content['type'] == 2) {
					$dd['name' . $kk] = $content['score'] == 10 ? '是' : '否';
				} else {

					$dd['name' . $kk] = $content['answer'] ? $content['answer'] : '';
				}

			}
			$dd['create_time']=Date('Y-m-d',strtotime($value['create_time']));
			$lists[] = $dd;

		}

		return $lists;
	}
/**
 * 获取列表
 * @param array $where
 * @return \think\Collection
 * @throws \think\db\exception\DataNotFoundException
 * @throws \think\db\exception\DbException
 * @throws \think\db\exception\ModelNotFoundException
 */
	public function getList(array $param = []) {
		$filter = [];
		// 查询参数
		$params = $this->setQueryDefaultValue($param, [
			'title' => '', // 文章标题
			'categoryId' => 0, // 文章分类id
			'status' => -1, // 文章状态
			'betweenTime' => [], // 起止时间
		]);
		$params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']];
		$params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
		if (!empty($params['title'])) {
			$filter[] = ['content', 'like', '%' . $params['title'] . '%'];
		}
		// 起止时间
		if (!empty($params['betweenTime'])) {
			$times = between_time($params['betweenTime']);
			$filter[] = ['create_time', '>=', $times['start_time']];
			$filter[] = ['create_time', '<', $times['end_time'] + 86400];
		}
		return $this->with(['user.avatar'])->where($filter)
			->order('create_time desc')
			->paginate(15);
	}
	/**
	 * 删除商品分类
	 * @param int $TimeId
	 * @return bool
	 */
	public function remove(): bool {

		// 删除记录
		return $this->delete();
	}
}
